//
//  TKHomeViewController.m
//  Ticket
//
//  Created by 小禹宝宝 on 2017/10/9.
//  Copyright © 2017年 cy55. All rights reserved.
//

#import "TKHomeViewController.h"
#import "TKTieziViewController.h"

//test
#import "TKLoginController.h"

#import "TKGoodsListResquest.h"

@interface TKHomeViewController()

@property (nonatomic, strong) UIButton *rightBtn;
@property (nonatomic, strong) TKTieziViewController *yanchuViewController;
@property (nonatomic, strong) TKTieziViewController *sportsEventViewController;
@property (nonatomic, strong) TKTieziViewController *exhibitionViewController;

@end
@implementation TKHomeViewController

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self configNavigationBar];
//    _navigationBar.alpha = 0.00f;
    self.navigationItem.title = @"动态";
    self.yanchuViewController = [[TKTieziViewController alloc] init];
    self.yanchuViewController.listType = TKTieZiListTypeYanchu;
    self.sportsEventViewController = [[TKTieziViewController alloc] init];
    self.sportsEventViewController.listType = TKTieZiListTypeSaishi;
    self.exhibitionViewController = [[TKTieziViewController alloc] init];
    self.exhibitionViewController.listType = TKTieZiListTypeZhanlan;
    
    [self.segmentedPager bl_defaultConfig];
//    The padding from the top, left, right, and bottom of the segmentedControl
    self.segmentedPager.segmentedControlEdgeInsets = UIEdgeInsetsMake(0, 50, 0, 50);
//    self.segmentedPager.backgroundColor = [BLColorConfig mainColor];
    
//    self.rightBtn = [self ks_setupRightButtonItemWithTitle:@"发帖"
//                                                     image:nil
//                                          highLightedImage:nil];
//    self.rightBtn.hidden = YES;
//        [self testRequest_DirectGetOrPost];
    
    //刷新帖子
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nfTieziPublished:) name:kNotificationTieziPublished object:nil];
}


- (void)configNavigationBar {
    _navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), 64)];
    [_navigationBar setBackgroundImage:[UIImage jc_createImageWithColor:[UIColor redColor]] forBarMetrics:UIBarMetricsDefault];
    [_navigationBar setShadowImage:[UIImage new]];;
    [_navigationBar setTranslucent:NO];
    [self.view addSubview:_navigationBar];
}

- (void)testRequest_DirectGetOrPost {
    
    DDLogVerbose(@"测试请求:%@",URL_test);
    NSDictionary *parameters = @{@"goods_id":@"9"};
    [BLApi GET:URL_GoodsDetail_info parameters:parameters decodeClass:nil completion:^(id responseObject, id responseDataOriginal, NSError *error) {
        DDLogInfo(@"URL_goodsinfo_get-responseObject:%@", responseDataOriginal);
    }];
    
}

- (void)ks_leftButtonPressed:(id)sender {
    //登录测试
    [SystemHelper presentLoginViewController];

    
}
- (void)nfTieziPublished:(NSNotification *)info {
    NSDictionary *dict = info.userInfo;
    NSString *category_id = dict[@"category_id"];
    int type = [category_id intValue];
    [self.segmentedPager.pager showPageAtIndex:type-1 animated:YES];
    self.segmentedPager.segmentedControl.selectedSegmentIndex = type-1;
    //对应控制器刷新数据
    switch (type) {
        case 1:
        {
            [self.yanchuViewController refreshData];
        }
            break;
        case 2:
        {
            [self.sportsEventViewController refreshData];

        }
            break;
        case 3:
        {
            [self.exhibitionViewController refreshData];

        }
            break;
            
        default:
            break;
    }
}

#pragma mark <MXSegmentedPagerControllerDataSource>

- (CGFloat)heightForSegmentedControlInSegmentedPager:(MXSegmentedPager *)segmentedPager {
    return 51;
}

- (NSInteger)numberOfPagesInSegmentedPager:(MXSegmentedPager *)segmentedPager {
    return 3;
}

- (NSString *)segmentedPager:(MXSegmentedPager *)segmentedPager titleForSectionAtIndex:(NSInteger)index {
    if (index == 0) {
        return @"演出";
    } else if (index == 1) {
        return @"体育赛事";
    } else {
        return @"休闲展览";
    }
}


- (UIViewController *)segmentedPager:(MXSegmentedPager *)segmentedPager viewControllerForPageAtIndex:(NSInteger)index {
    if (index == 0) {
        return self.yanchuViewController;
    } else if (index == 1) {
        return self.sportsEventViewController;
    } else {
        return self.exhibitionViewController;
    }
}

- (void)segmentedPager:(MXSegmentedPager *)segmentedPager didSelectViewWithIndex:(NSInteger)index {
//    self.rightBtn.hidden = index == 0;
}
@end
